//
//
package com.eliza.module.view.work.sherlockholmes;
//
//import static androidx.work.WorkInfo.State.FAILED;
//import static androidx.work.WorkInfo.State.SUCCEEDED;
//
//import android.os.Bundle;
//import android.view.View;
//import android.widget.Button;
//import android.widget.ProgressBar;
//import android.widget.TextView;
//
//import androidx.appcompat.app.AppCompatActivity;
//import androidx.work.ArrayCreatingInputMerger;
//import androidx.work.OneTimeWorkRequest;
//import androidx.work.WorkInfo;
//import androidx.work.WorkManager;
//
//import com.eliza.background.R;
//import com.eliza.background.view.work.db.TestDatabase;
//import com.eliza.background.view.work.db.WordCount;
//
//import java.util.Arrays;
//import java.util.List;
//
///**
// * Analyze Sherlock Holmes activity.
// */
//public class AnalyzeSherlockHolmesActivity extends AppCompatActivity {
//    private Button mAnalyzeButton;
//    private ProgressBar mProgressBar;
//    private TextView mResultsView;
//
//    final StringBuilder mStringBuilder = new StringBuilder();
//
//    @Override
//    protected void onCreate(final Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_analyze_sherlock_holmes);
//
//        mAnalyzeButton = findViewById(R.id.analyze);
//        mAnalyzeButton.setOnClickListener(v -> enqueueWork());
//
//        mProgressBar = findViewById(R.id.progress);
//        mProgressBar.setVisibility(View.GONE);
//        mResultsView = findViewById(R.id.results);
//        mResultsView.setVisibility(View.GONE);
//
//        TestDatabase.getInstance(this).getWordCountDao().getWordCounts().observe(
//                this,
//                wordCounts -> {
//                    if (wordCounts == null) {
//                        return;
//                    }
//                    mResultsView.setText(getWordCountsString(wordCounts));
//                });
//    }
//
//    private void enqueueWork() {
//        WorkManager workManager = WorkManager.getInstance(AnalyzeSherlockHolmesActivity.this);
//
//        // Cancelling all work just to make it easier to track what is happening here and make it
//        // more insulated.
//        workManager.cancelAllWork();
//
//        OneTimeWorkRequest textReducingWork =
//                new OneTimeWorkRequest.Builder(TextReducingWorker.class)
//                    .setInputMerger(ArrayCreatingInputMerger.class)
//                    .build();
//
//        OneTimeWorkRequest startupWork =
//                new OneTimeWorkRequest.Builder(TextStartupWorker.class).build();
//
//        workManager
//                .beginWith(startupWork)
//                .then(Arrays.asList(TextMappingWorker.create("advs.txt").build(),
//                        TextMappingWorker.create("case.txt").build(),
//                        TextMappingWorker.create("lstb.txt").build(),
//                        TextMappingWorker.create("mems.txt").build(),
//                        TextMappingWorker.create("retn.txt").build()))
//                .then(textReducingWork)
//                .enqueue();
//
//        workManager.getWorkInfoByIdLiveData(textReducingWork.getId()).observe(
//                this,
//                status -> {
//                    boolean loading = (status != null
//                            && status.getState() != WorkInfo.State.SUCCEEDED
//                            && status.getState() != WorkInfo.State.FAILED);
//                    mProgressBar.setVisibility(loading ? View.VISIBLE : View.GONE);
//                    mResultsView.setVisibility(loading ? View.GONE : View.VISIBLE);
//                    mAnalyzeButton.setEnabled(!loading);
//                }
//        );
//    }
//
//    private String getWordCountsString(List<WordCount> wordCounts) {
//        // TODO: not efficient, this should be part of its own LiveData thing.
//        mStringBuilder.setLength(0);
//        for (WordCount wc : wordCounts) {
//            mStringBuilder
//                    .append(wc.mWord)
//                    .append(" ")
//                    .append(wc.mCount)
//                    .append("\n");
//        }
//        return mStringBuilder.toString();
//    }
//}
